package com.op.teachingliteapp.fragment;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.op.teachingliteapp.R;

public class SettingsFragment extends Fragment {

	View root;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		root = inflater.inflate(R.layout.fragment_settings, container, false);

		// 退出程序按钮
		root.findViewById(R.id.outApp).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						dialog();
					}
				});

		return root;
	}

	// 对话框退出程序
	protected void dialog() {
		AlertDialog.Builder builder = new Builder(getActivity());
		builder.setMessage("确认退出吗？");
		builder.setTitle("提示");
		builder.setNeutralButton("确认", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent intent = new Intent(Intent.ACTION_MAIN);
				intent.addCategory(Intent.CATEGORY_HOME);
				startActivity(intent);
				System.exit(0);// 使虚拟机停止运行并退出程序
				getActivity().finish();
			}
		});
		builder.setNegativeButton("取消", null);
		builder.create();
		builder.show();
	}

}
